
package Connect;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


public class Connect {
        //Method conect to sql server
        public static Connection Con(){
        //  add Library: sqljdbc.jar
        String url = "jdbc:sqlserver://localhost:1433;instanceName=MANHHAO-PC;database=Cross_Word_database";
        Connection conn = null;
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = java.sql.DriverManager.getConnection(url,"admin","admin");            
        }catch(Exception e){
           JOptionPane.showMessageDialog(null, "Can not connect to database !","Database Error",JOptionPane.ERROR_MESSAGE);
        }
        return conn;
    }
}
